<template>
  <div class="exam-management">


    <!-- 功能区 -->
    <div class="function-area">
      <div class="search-section">
        <div class="search-item">
          <label>监考类型：</label>
          <select v-model="searchParams.examType" class="search-select">
            <option value="">全部</option>
            <option value="exam1">常规监考</option>
            <option value="exam2">特殊监考</option>
            <option value="exam3">研究生监考</option>
          </select>
        </div>

        <div class="search-item">
          <label>监考名称：</label>
          <input
              type="text"
              v-model="searchParams.examName"
              placeholder="请输入监考名称关键词查询"
              class="search-input"
          >
        </div>

        <div class="action-buttons">
          <button class="query-btn" @click="searchExams">查询</button>
          <button class="reset-btn" @click="resetSearch">重置</button>
          <button class="quick-btn" @click="quickFind">快速找人</button>
          <button class="create-btn" @click="createBatch">创建批次</button>
          <button class="export-btn" @click="exportData">数据导出</button>
        </div>
      </div>
    </div>

    <!-- 监考批次表格 -->
    <div class="exam-table">
      <table>
        <thead>
        <tr>
          <th>序号</th>
          <th>监考名称</th>
          <th>报名情况</th>
          <th>报名开始时间</th>
          <th>报名结束时间</th>
          <th>创建时间</th>
          <th>批次状态</th>
          <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr v-for="(batch, index) in filteredBatches" :key="batch.id">
          <td>{{ index + 1 }}</td>
          <td>
            <a href="javascript:void(0)" @click="viewApplicants(batch.id)">
              {{ batch.name }}
            </a>
          </td>
          <td>{{ batch.applied }}/{{ batch.total }}</td>
          <td>{{ formatDate(batch.startTime) }}</td>
          <td>{{ formatDate(batch.endTime) }}</td>
          <td>{{ formatDate(batch.createTime) }}</td>
          <td>
            <span :class="getStatusClass(batch.status)">{{ batch.statusText }}</span>
          </td>
          <td>
            <button class="view-btn" @click="viewApplicants(batch.id)">查看名单</button>
            <button class="more-btn" @click="showMoreOptions(batch)">更多</button>
          </td>
        </tr>
        </tbody>
      </table>
    </div>

    <!-- 报名表预览弹窗 -->
    <div v-if="showPreview" class="preview-modal">
      <div class="modal-content">
        <div class="modal-header">
          <h3>武汉理工大学研究生招生考试监考人员报名表</h3>
          <button class="close-btn" @click="showPreview = false">&times;</button>
        </div>

        <div class="modal-body">
          <div class="form-row">
            <div class="form-col">
              <div class="form-item">
                <label>姓名：</label>
                <span>{{ previewData.name }}</span>
              </div>
              <div class="form-item">
                <label>性别：</label>
                <span>{{ previewData.gender }}</span>
              </div>
              <div class="form-item">
                <label>学历：</label>
                <span>{{ previewData.education }}</span>
              </div>
              <div class="form-item">
                <label>出生年月：</label>
                <span>{{ previewData.birthDate }}</span>
              </div>
            </div>

            <div class="form-col">
              <div class="form-item">
                <label>单位：</label>
                <span>{{ previewData.department }}</span>
              </div>
              <div class="form-item">
                <label>工号：</label>
                <span>{{ previewData.workId }}</span>
              </div>
              <div class="form-item">
                <label>手机号：</label>
                <span>{{ previewData.phone }}</span>
              </div>
              <div class="form-item">
                <label>备用电话：</label>
                <span>{{ previewData.backupPhone }}</span>
              </div>
            </div>
          </div>

          <div class="form-section">
            <label>电子照片：</label>
            <div class="photo-placeholder">
              <div class="plus-icon">+</div>
              <div class="upload-text">上传照片</div>
            </div>
          </div>

          <div class="form-section">
            <label>监考校区：</label>
            <div class="campus-options">
              <div v-for="(campus, index) in campuses" :key="index" class="campus-option">
                <input
                    type="checkbox"
                    :id="'campus'+index"
                    :checked="campus.checked"
                    disabled
                >
                <label :for="'campus'+index">{{ campus.name }}</label>
              </div>
            </div>
          </div>

          <div class="form-section conditions">
            <h4>监考人员基本条件：</h4>
            <ol>
              <li>政治立场坚定，思想品德良好，工作认真负责，能按时参加考务培训及考核且胜任监考工作；</li>
              <li>学校在编在岗教职工，身体健康，考前14天（12月10日-23日）健康监测情况正常；</li>
              <li>无直系亲属或者利害关系人参加本年度全国硕士研究生招生考试；</li>
              <li>熟悉考试政策规定、有监考工作经验者优先。</li>
            </ol>
          </div>

          <div class="form-section">
            <h4>申请人承诺：</h4>
            <p>本人自愿参加研究生入学考试监考工作，认真学习掌握工作纪律要求，严格遵守《国家教育考试考务安全保密工作规定》，切实遵守监考工作守则，按照考务工作安排，完成监考工作。</p>
            <div class="signature">
              <div>申请人：{{ previewData.name }}</div>
              <div>日期：{{ previewData.applyDate }}</div>
            </div>
          </div>

          <div class="form-section">
            <h4>所在单位意见：</h4>
            <div class="signature-area">
              <div class="signature-line">
                <span>领导签字：</span>
                <div class="signature-placeholder"></div>
              </div>
              <div class="signature-line">
                <span>单位盖章：</span>
                <div class="stamp-placeholder"></div>
              </div>
              <div class="signature-line">
                <span>日期：</span>
                <span>{{ previewData.applyDate }}</span>
              </div>
            </div>
          </div>

          <div class="form-section">
            <label>备注：</label>
            <div class="remarks">{{ previewData.remarks }}</div>
          </div>
        </div>
      </div>
    </div>

    <!-- 更多操作弹窗 -->
    <div v-if="showMoreMenu" class="more-menu-modal">
      <div class="menu-content">
        <button @click="editBatch(selectedBatch)">编辑批次</button>
        <button @click="deleteBatch(selectedBatch)">删除批次</button>
        <button @click="exportBatch(selectedBatch)">导出名单</button>
        <button @click="closeMenu">关闭</button>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, onMounted } from 'vue';

// 搜索参数
const searchParams = ref({
  examType: '',
  examName: ''
});

// 监考批次数据
const examBatches = ref([
  {
    id: 1,
    name: '2023年A级2023监考批次',
    applied: 0,
    total: 22,
    startTime: '2023-10-18T16:57:35',
    endTime: '2023-12-18T16:57:35',
    createTime: '2023-10-17T16:57:35',
    status: 'not-started',
    statusText: '未开始'
  },
  {
    id: 2,
    name: '2023年B级2023监考批次',
    applied: 12,
    total: 22,
    startTime: '2023-10-18T16:57:35',
    endTime: '2023-11-18T16:57:35',
    createTime: '2023-10-17T16:57:35',
    status: 'in-progress',
    statusText: '进行中'
  },
  {
    id: 3,
    name: '2023年C级2023监考批次',
    applied: 22,
    total: 22,
    startTime: '2023-09-18T16:57:35',
    endTime: '2023-10-18T16:57:35',
    createTime: '2023-09-17T16:57:35',
    status: 'ended',
    statusText: '已结束'
  },
  {
    id: 4,
    name: '2023年D级2023监考批次',
    applied: 18,
    total: 22,
    startTime: '2023-08-18T16:57:35',
    endTime: '2023-09-18T16:57:35',
    createTime: '2023-08-17T16:57:35',
    status: 'ended',
    statusText: '已结束'
  }
]);

// 校区选项
const campuses = ref([
  { id: 'nh', name: '南湖校区', checked: true },
  { id: 'yjt', name: '余家头校区', checked: false },
  { id: 'fc', name: '服从调剂', checked: true }
]);

// 预览数据
const previewData = ref({
  name: '张三',
  department: '计算机学院',
  gender: '男',
  workId: '10001',
  education: '博士',
  phone: '13800138000',
  backupPhone: '13800138001',
  birthDate: '1985-01-01',
  applyDate: '2023-09-15',
  remarks: '无特殊要求'
});

// 弹窗控制
const showPreview = ref(false);
const showMoreMenu = ref(false);
const selectedBatch = ref(null);
import { useRouter } from 'vue-router'; // 添加导入
const router = useRouter(); // 添加路由实例
// 过滤后的监考批次
const filteredBatches = computed(() => {
  return examBatches.value.filter(batch => {
    const matchesType = !searchParams.value.examType ||
        batch.name.includes(searchParams.value.examType);
    const matchesName = !searchParams.value.examName ||
        batch.name.toLowerCase().includes(searchParams.value.examName.toLowerCase());
    return matchesType && matchesName;
  });
});

// 日期格式化
const formatDate = (dateString: string) => {
  const date = new Date(dateString);
  return `${date.getFullYear()}/${(date.getMonth() + 1).toString().padStart(2, '0')}/${date.getDate().toString().padStart(2, '0')} ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}:${date.getSeconds().toString().padStart(2, '0')}`;
};

// 获取状态类名
const getStatusClass = (status: string) => {
  return {
    'not-started': 'status-not-started',
    'in-progress': 'status-in-progress',
    'ended': 'status-ended'
  }[status] || '';
};

// 搜索监考批次
const searchExams = () => {
  console.log('搜索条件:', searchParams.value);
};

// 重置搜索
const resetSearch = () => {
  searchParams.value = {
    examType: '',
    examName: ''
  };
};

// 快速找人
const quickFind = () => {
  alert('快速找人功能');
};

// 创建批次
const createBatch = () => {
  router.push('/dashboard3/create-batch'); // 修改为路由跳转
};

// 导出数据
const exportData = () => {
  alert('数据导出');
};

// 查看报名人员 - 修改为路由跳转
const viewApplicants = (batchId: number) => {
  router.push(`/dashboard3/exam-management/applicants/${batchId}`);
};

// 显示更多选项
const showMoreOptions = (batch: any) => {
  selectedBatch.value = batch;
  showMoreMenu.value = true;
};

// 关闭菜单
const closeMenu = () => {
  showMoreMenu.value = false;
};

// 编辑批次
const editBatch = (batch: any) => {
  alert(`编辑批次: ${batch.name}`);
  closeMenu();
};

// 删除批次
const deleteBatch = (batch: any) => {
  if (confirm(`确定要删除批次 "${batch.name}" 吗？`)) {
    examBatches.value = examBatches.value.filter(b => b.id !== batch.id);
  }
  closeMenu();
};

// 导出批次
const exportBatch = (batch: any) => {
  alert(`导出批次: ${batch.name}`);
  closeMenu();
};



</script>

<style scoped>
.exam-management {
  background-color: #f8fafc;
  padding: 20px;
  border-radius: 8px;
  min-height: calc(100vh - 40px);
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
  padding-bottom: 15px;
  border-bottom: 2px solid #1a3a6c;
}

.header h1 {
  margin: 0;
  font-size: 24px;
  color: #1a2b4b;
}

.user-info {
  display: flex;
  align-items: center;
}

.avatar-placeholder {
  width: 45px;
  height: 45px;
  border-radius: 50%;
  background-color: #1a3a6c;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 20px;
  margin-right: 12px;
}

.user-details p {
  margin: 0;
  line-height: 1.4;
}

.username {
  font-weight: 600;
  color: #1a2b4b;
}

.role {
  font-size: 14px;
  color: #666;
}

.function-area {
  background-color: white;
  padding: 20px;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin-bottom: 25px;
}

.search-section {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  align-items: center;
}

.search-item {
  display: flex;
  align-items: center;
}

.search-item label {
  font-weight: 600;
  color: #1a2b4b;
  min-width: 80px;
}

.search-select, .search-input {
  padding: 8px 12px;
  border: 1px solid #d9d9d9;
  border-radius: 4px;
  min-width: 200px;
}

.search-input {
  width: 250px;
}

.action-buttons {
  display: flex;
  gap: 12px;
  margin-left: 15px;
}

.action-buttons button {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.3s;
}

.query-btn {
  background-color: #1a3a6c;
  color: white;
}

.query-btn:hover {
  background-color: #0d2a56;
}

.reset-btn {
  background-color: #f0f2f5;
  color: #1a2b4b;
}

.reset-btn:hover {
  background-color: #e2e8f0;
}

.quick-btn, .create-btn, .export-btn {
  background-color: #f0f2f5;
  color: #1a2b4b;
  border: 1px solid #d9d9d9;
}

.quick-btn:hover, .create-btn:hover, .export-btn:hover {
  background-color: #e2e8f0;
}

.exam-table {
  background-color: white;
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  padding: 20px;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 12px 15px;
  text-align: left;
  border-bottom: 1px solid #e8e8e8;
}

th {
  background-color: #f0f2f5;
  color: #1a2b4b;
  font-weight: 600;
}

tbody tr:hover {
  background-color: #f8fafc;
}

.status-not-started, .status-in-progress, .status-ended {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
}

.status-not-started {
  background-color: #f0f2f5;
  color: #666;
}

.status-in-progress {
  background-color: #e6f7ff;
  color: #1890ff;
}

.status-ended {
  background-color: #f6ffed;
  color: #52c41a;
}

.view-btn, .more-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

.view-btn {
  background-color: #e6f7ff;
  color: #1890ff;
  margin-right: 8px;
}

.more-btn {
  background-color: #f0f2f5;
  color: #666;
}

.view-btn:hover {
  background-color: #bae7ff;
}

.more-btn:hover {
  background-color: #e2e8f0;
}

/* 弹窗样式 */
.preview-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background-color: white;
  width: 90%;
  max-width: 900px;
  max-height: 90vh;
  border-radius: 8px;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  background-color: #1a3a6c;
  color: white;
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
}

.modal-header h3 {
  margin: 0;
  font-size: 20px;
}

.close-btn {
  background: none;
  border: none;
  color: white;
  font-size: 28px;
  cursor: pointer;
  padding: 0 10px;
}

.modal-body {
  padding: 25px;
}

.form-row {
  display: flex;
  gap: 30px;
  margin-bottom: 20px;
}

.form-col {
  flex: 1;
}

.form-item {
  display: flex;
  margin-bottom: 15px;
  padding-bottom: 10px;
  border-bottom: 1px dashed #e8e8e8;
}

.form-item label {
  font-weight: 600;
  min-width: 100px;
  color: #1a2b4b;
}

.form-section {
  margin-bottom: 25px;
}

.form-section label {
  font-weight: 600;
  color: #1a2b4b;
  display: block;
  margin-bottom: 10px;
}

.photo-placeholder {
  width: 150px;
  height: 200px;
  border: 1px dashed #d9d9d9;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: #fafafa;
}

.plus-icon {
  font-size: 40px;
  color: #8c8c8c;
  line-height: 1;
}

.upload-text {
  margin-top: 10px;
  color: #8c8c8c;
}

.campus-options {
  display: flex;
  gap: 25px;
  margin-top: 10px;
}

.campus-option {
  display: flex;
  align-items: center;
}

.campus-option input {
  margin-right: 8px;
}

.conditions ol {
  padding-left: 25px;
}

.conditions li {
  margin-bottom: 10px;
  line-height: 1.6;
}

.signature {
  margin-top: 20px;
  text-align: right;
  font-weight: 600;
}

.signature-area {
  margin-top: 20px;
}

.signature-line {
  display: flex;
  align-items: center;
  margin-bottom: 15px;
}

.signature-line span {
  min-width: 100px;
  font-weight: 600;
}

.signature-placeholder {
  flex: 1;
  height: 30px;
  border-bottom: 1px solid #333;
}

.stamp-placeholder {
  width: 120px;
  height: 120px;
  border: 1px dashed #d9d9d9;
  background-color: #fafafa;
  margin-top: 10px;
}

.remarks {
  padding: 10px;
  border: 1px solid #e8e8e8;
  border-radius: 4px;
  min-height: 80px;
  background-color: #fafafa;
}

/* 更多菜单弹窗 */
.more-menu-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.menu-content {
  background-color: white;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  min-width: 180px;
}

.menu-content button {
  display: block;
  width: 100%;
  padding: 12px 20px;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.3s;
}

.menu-content button:hover {
  background-color: #f0f2f5;
}

.menu-content button:not(:last-child) {
  border-bottom: 1px solid #e8e8e8;
}
</style>